;; Tests of the Non-robust linear algebra functions
;; Copyright (C) 2021  Rocks Mazama
;; 
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; 
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;; 
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

(ns mazama.linalg.tridiagonal-test
  (:require
   [clojure.test :refer [deftest is testing]]
   [mazama.linalg.tridiagonal :refer :all]))

(deftest tridiagonal-test
  (testing "https://matlabgeeks.weebly.com/uploads/8/0/4/8/8048228/thomas_algorithm_and_tridiagonal_matrix-_example.pdf"
    (let [a (take 3 (repeat 1))
          b (take 4 (repeat -26/10))
          c (take 3 (repeat 1))
          d [-240 0 0 -150]
          result (map #(Math/round (float %)) (tridiagonal a b c d))]
      (is (= [118 67 56 79] result))))
  (testing "http://www.public.asu.edu/~hhuang38/pde_slides_bvp_correct.pdf"
    (let [a (take 3 (repeat 1))
          b (take 4 (repeat -2))
          c (take 3 (repeat 1))
          d (take 4 (repeat 4/100))
          result (tridiagonal a b c d)]
      (is (= [-8/100 -12/100 -12/100 -8/100] result)))))
